Permalink
Comparing changes
Open a pull request
- 5 commits
- 22 files changed
- 0 commit comments
- 1 contributor
Commits on Mar 21, 2015
Unified
Split
Showing
with
278 additions
and 20 deletions.
- +38 −0 src/Bindings/LuaState.cpp
- +6 −0 src/Bindings/LuaState.h
- +55 −0 src/Bindings/ManualBindings.cpp
- +47 −0 src/Broadcaster.cpp
- +18 −0 src/Broadcaster.h
- +2 −0 src/CMakeLists.txt
- +3 −3 src/Chunk.h
- +22 −0 src/ChunkMap.cpp
- +2 −0 src/ChunkMap.h
- +6 −0 src/ClientHandle.cpp
- +1 −0 src/ClientHandle.h
- +3 −3 src/Entities/Floater.cpp
- +3 −2 src/Mobs/Wolf.cpp
- +1 −0 src/Protocol/Protocol.h
- +5 −2 src/Protocol/Protocol17x.cpp
- +1 −0 src/Protocol/Protocol17x.h
- +38 −0 src/Protocol/Protocol18x.cpp
- +1 −0 src/Protocol/Protocol18x.h
- +6 −0 src/Protocol/ProtocolRecognizer.cpp
- +1 −0 src/Protocol/ProtocolRecognizer.h
- +14 −9 src/World.cpp
- +5 −1 src/World.h
| @@ -1133,6 +1133,23 @@ void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal) | ||
| void cLuaState::GetStackValue(int a_StackPos, pClientHandle & a_ReturnedVal) | ||
| { | ||
| if (lua_isnil(m_LuaState, a_StackPos)) | ||
| { | ||
| a_ReturnedVal = nullptr; | ||
| return; | ||
| } | ||
| tolua_Error err; | ||
| if (tolua_isusertype(m_LuaState, a_StackPos, "cClientHandle", false, &err)) | ||
| { | ||
| a_ReturnedVal = *(reinterpret_cast<cClientHandle **>(lua_touserdata(m_LuaState, a_StackPos))); | ||
| } | ||
| } | ||
| bool cLuaState::CallFunction(int a_NumResults) | ||
| { | ||
| ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first | ||
| @@ -1415,6 +1432,27 @@ bool cLuaState::CheckParamEnd(int a_Param) | ||
| bool cLuaState::IsParamUserType(int a_Param, AString a_UserType) | ||
| { | ||
| ASSERT(IsValid()); | ||
| tolua_Error tolua_err; | ||
| return tolua_isusertype(m_LuaState, a_Param, a_UserType.c_str(), 0, &tolua_err); | ||
| } | ||
| bool cLuaState::IsParamNumber(int a_Param) | ||
| { | ||
| ASSERT(IsValid()); | ||
| tolua_Error tolua_err; | ||
| return tolua_isnumber(m_LuaState, a_Param, 0, &tolua_err); | ||
| } | ||
| bool cLuaState::ReportErrors(int a_Status) | ||
| { | ||
| return ReportErrors(m_LuaState, a_Status); | ||
| @@ -76,6 +76,7 @@ typedef cPluginManager * pPluginManager; | ||
| typedef cRoot * pRoot; | ||
| typedef cScoreboard * pScoreboard; | ||
| typedef cWorld * pWorld; | ||
| typedef cClientHandle * pClientHandle; | ||
| @@ -259,6 +260,7 @@ class cLuaState | ||
| void GetStackValue(int a_StackPos, pRoot & a_Value); | ||
| void GetStackValue(int a_StackPos, pScoreboard & a_Value); | ||
| void GetStackValue(int a_StackPos, pWorld & a_Value); | ||
| void GetStackValue(int a_StackPos, pClientHandle & a_Value); | ||
| /** Call the specified Lua function. | ||
| Returns true if call succeeded, false if there was an error. | ||
| @@ -307,6 +309,10 @@ class cLuaState | ||
| /** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */ | ||
| bool CheckParamEnd(int a_Param); | ||
| bool IsParamUserType(int a_Param, AString a_UserType); | ||
| bool IsParamNumber(int a_Param); | ||
| /** If the status is nonzero, prints the text on the top of Lua stack and returns true */ | ||
| bool ReportErrors(int status); | ||
| @@ -32,6 +32,7 @@ | ||
| #include "../WorldStorage/SchematicFileSerializer.h" | ||
| #include "../CompositeChat.h" | ||
| #include "../StringCompression.h" | ||
| #include "../Broadcaster.h" | ||
| @@ -2009,6 +2010,59 @@ static int tolua_cPluginManager_FindPlugins(lua_State * tolua_S) | ||
| static int tolua_cWorld_BroadcastParticleEffect(lua_State * tolua_S) | ||
| { | ||
| cLuaState L(tolua_S); | ||
| if ( | ||
| !L.CheckParamUserType(1, "cWorld") || | ||
| !L.CheckParamString (2) || | ||
| !L.CheckParamNumber (3, 10) | ||
| ) | ||
| { | ||
| return 0; | ||
| } | ||
| cPluginLua * Plugin = GetLuaPlugin(tolua_S); | ||
| if (Plugin == nullptr) | ||
| { | ||
| return 0; | ||
| } | ||
| // Read the params: | ||
| cWorld * World = nullptr; | ||
| AString Name; | ||
| double PosX, PosY, PosZ, OffX, OffY, OffZ; | ||
| double ParticleData; | ||
| int ParticleAmmount; | ||
| L.GetStackValues(1, World, Name, PosX, PosY, PosZ, OffX, OffY, OffZ, ParticleData, ParticleAmmount); | ||
| if (World == nullptr) | ||
| { | ||
| LOGWARNING("World:BroadcastParticleEffect(): invalid world parameter"); | ||
| L.LogStackTrace(); | ||
| return 0; | ||
| } | ||
| std::array<int, 2> data; | ||
| for (int i = 0; (i < 2) && L.IsParamNumber(11 + i); i++) | ||
| { | ||
| L.GetStackValue(11 + i, data[i]); | ||
| } | ||
| cClientHandle * Exclude = nullptr; | ||
| if (L.IsParamUserType(11, "cClientHandle")) | ||
| { | ||
| L.GetStackValue(11, Exclude); | ||
| } | ||
| World->GetBroadcaster().BroadcastParticleEffect(Name, Vector3f(PosX, PosY, PosZ), Vector3f(OffX, OffY, OffZ), ParticleData, ParticleAmmount, Exclude); | ||
| return 0; | ||
| } | ||
| static int tolua_cWorld_ChunkStay(lua_State * tolua_S) | ||
| { | ||
| /* Function signature: | ||
| @@ -3792,6 +3846,7 @@ void ManualBindings::Bind(lua_State * tolua_S) | ||
| tolua_endmodule(tolua_S); | ||
| tolua_beginmodule(tolua_S, "cWorld"); | ||
| tolua_function(tolua_S, "BroadcastParticleEffect", tolua_cWorld_BroadcastParticleEffect); | ||
| tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay); | ||
| tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>); | ||
| tolua_function(tolua_S, "DoWithBeaconAt", tolua_DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>); | ||
| @@ -0,0 +1,47 @@ | ||
| #include "Globals.h" | ||
| #include "Broadcaster.h" | ||
| #include "World.h" | ||
| #include "Chunk.h" | ||
| cBroadcaster::cBroadcaster(cWorld * a_World) : | ||
| m_World(a_World) | ||
| { | ||
| } | ||
| void cBroadcaster::BroadcastParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude) | ||
| { | ||
| m_World->DoWithChunkAt(a_Src, | ||
| [=](cChunk& a_Chunk) -> bool | ||
| { | ||
| for (auto&& client : a_Chunk.GetAllClients()) | ||
| { | ||
| if (client == a_Exclude) | ||
| { | ||
| continue; | ||
| } | ||
| client->SendParticleEffect(a_ParticleName, a_Src.x, a_Src.y, a_Src.z, a_Offset.x, a_Offset.y, a_Offset.z, a_ParticleData, a_ParticleAmount); | ||
| }; | ||
| return true; | ||
| }); | ||
| } | ||
| void cBroadcaster::BroadcastParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data, cClientHandle * a_Exclude) | ||
| { | ||
| m_World->DoWithChunkAt(a_Src, | ||
| [=](cChunk& a_Chunk) -> bool | ||
| { | ||
| for (auto&& client : a_Chunk.GetAllClients()) | ||
| { | ||
| if (client == a_Exclude) | ||
| { | ||
| continue; | ||
| } | ||
| client->SendParticleEffect(a_ParticleName, a_Src, a_Offset, a_ParticleData, a_ParticleAmount, data); | ||
| }; | ||
| return true; | ||
| }); | ||
| } | ||
| @@ -0,0 +1,18 @@ | ||
| class cWorld; | ||
| class cBroadcaster | ||
| { | ||
| public: | ||
| cBroadcaster(cWorld * a_World); | ||
| void BroadcastParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude = nullptr); | ||
| void BroadcastParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data, cClientHandle * a_Exclude = nullptr); | ||
| private: | ||
| cWorld * m_World; | ||
| }; |
| @@ -18,6 +18,7 @@ SET (SRCS | ||
| BlockArea.cpp | ||
| BlockID.cpp | ||
| BlockInfo.cpp | ||
| Broadcaster.cpp | ||
| BoundingBox.cpp | ||
| ByteBuffer.cpp | ||
| ChatColor.cpp | ||
| @@ -77,6 +78,7 @@ SET (HDRS | ||
| BlockInServerPluginInterface.h | ||
| BlockInfo.h | ||
| BlockTracer.h | ||
| Broadcaster.h | ||
| BoundingBox.h | ||
| BuildInfo.h.cmake | ||
| ByteBuffer.h | ||
| @@ -439,6 +439,9 @@ class cChunk : | ||
| as at least one requests is active the chunk will be ticked). */ | ||
| void SetAlwaysTicked(bool a_AlwaysTicked); | ||
| // Makes a copy of the list | ||
| cClientHandleList GetAllClients(void) const {return m_LoadedByClient; } | ||
| private: | ||
| friend class cChunkMap; | ||
| @@ -530,9 +533,6 @@ class cChunk : | ||
| /** Wakes up each simulator for its specific blocks; through all the blocks in the chunk */ | ||
| void WakeUpSimulators(void); | ||
| // Makes a copy of the list | ||
| cClientHandleList GetAllClients(void) const {return m_LoadedByClient; } | ||
| /** Sends m_PendingSendBlocks to all clients */ | ||
| void BroadcastPendingBlockChanges(void); | ||
| @@ -791,6 +791,28 @@ bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callb | ||
| } | ||
| bool cChunkMap::DoWithChunkAt(Vector3i a_Pos, std::function<bool(cChunk&)> a_Callback) | ||
| { | ||
| int ChunkX, ChunkZ; | ||
| cChunkDef::BlockToChunk(a_Pos.x, a_Pos.z, ChunkX, ChunkZ); | ||
| struct cCallBackWrapper : cChunkCallback | ||
| { | ||
| cCallBackWrapper(std::function<bool(cChunk&)> a_InnerCallback) : | ||
| m_Callback(a_InnerCallback) | ||
| { | ||
| } | ||
| virtual bool Item(cChunk * a_Chunk) | ||
| { | ||
| return m_Callback(*a_Chunk); | ||
| } | ||
| private: | ||
| std::function<bool(cChunk&)> m_Callback; | ||
| } callback(a_Callback); | ||
| return DoWithChunk(ChunkX, ChunkZ, callback); | ||
| } | ||
| @@ -104,6 +104,8 @@ class cChunkMap | ||
| /** Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback */ | ||
| bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback); | ||
| bool DoWithChunkAt(Vector3i a_Pos, std::function<bool(cChunk&)> a_Callback); | ||
| /** Wakes up simulators for the specified block */ | ||
| void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ); | ||
| @@ -2372,6 +2372,12 @@ void cClientHandle::SendParticleEffect(const AString & a_ParticleName, float a_S | ||
| void cClientHandle::SendParticleEffect(const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data) | ||
| { | ||
| m_Protocol->SendParticleEffect(a_ParticleName, a_Src, a_Offset, a_ParticleData, a_ParticleAmount, data); | ||
| } | ||
| void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup) | ||
| @@ -177,6 +177,7 @@ class cClientHandle // tolua_export | ||
| void SendMapInfo (int a_ID, unsigned int a_Scale); | ||
| void SendPaintingSpawn (const cPainting & a_Painting); | ||
| void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount); | ||
| void SendParticleEffect (const AString & a_ParticleName, const Vector3f a_Src, const Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data); | ||
| void SendPickupSpawn (const cPickup & a_Pickup); | ||
| void SendPlayerAbilities (void); | ||
| void SendPlayerListAddPlayer (const cPlayer & a_Player); | ||
| @@ -6,7 +6,7 @@ | ||
| #include "Floater.h" | ||
| #include "Player.h" | ||
| #include "../ClientHandle.h" | ||
| #include "Broadcaster.h" | ||
| @@ -145,12 +145,12 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) | ||
| { | ||
| LOGD("Started producing particles for floater %i", GetUniqueID()); | ||
| m_ParticlePos.Set(GetPosX() + (-4 + m_World->GetTickRandomNumber(8)), GetPosY(), GetPosZ() + (-4 + m_World->GetTickRandomNumber(8))); | ||
| m_World->BroadcastParticleEffect("splash", (float) m_ParticlePos.x, (float) m_ParticlePos.y, (float) m_ParticlePos.z, 0, 0, 0, 0, 15); | ||
| m_World->GetBroadcaster().BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f{}, 0, 15); | ||
| } | ||
| else if (m_CountDownTime < 20) | ||
| { | ||
| m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6); | ||
| m_World->BroadcastParticleEffect("splash", (float) m_ParticlePos.x, (float) m_ParticlePos.y, (float) m_ParticlePos.z, 0, 0, 0, 0, 15); | ||
| m_World->GetBroadcaster().BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f{}, 0, 15); | ||
| } | ||
| m_CountDownTime--; | ||
| @@ -5,6 +5,7 @@ | ||
| #include "../World.h" | ||
| #include "../Entities/Player.h" | ||
| #include "../Items/ItemHandler.h" | ||
| #include "Broadcaster.h" | ||
| @@ -83,13 +84,13 @@ void cWolf::OnRightClicked(cPlayer & a_Player) | ||
| SetIsTame(true); | ||
| SetOwner(a_Player.GetName(), a_Player.GetUUID()); | ||
| m_World->BroadcastEntityStatus(*this, esWolfTamed); | ||
| m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); | ||
| m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5); | ||
| } | ||
| else | ||
| { | ||
| // Taming failed | ||
| m_World->BroadcastEntityStatus(*this, esWolfTaming); | ||
| m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5); | ||
| m_World->GetBroadcaster().BroadcastParticleEffect("smoke", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5); | ||
| } | ||
| } | ||
| } | ||
| @@ -98,6 +98,7 @@ class cProtocol | ||
| virtual void SendPlayerAbilities (void) = 0; | ||
| virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0; | ||
| virtual void SendParticleEffect (const AString & a_SoundName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) = 0; | ||
| virtual void SendParticleEffect (const AString & a_SoundName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data) = 0; | ||
| virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) = 0; | ||
| virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) = 0; | ||
| virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) = 0; | ||
| @@ -800,8 +800,11 @@ void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_Sr | ||
| Pkt.WriteBEInt32(a_ParticleAmount); | ||
| } | ||
| void cProtocol172::SendParticleEffect(const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data) | ||
| { | ||
| // 1.72 doesn't support extra data | ||
| this->SendParticleEffect(a_ParticleName, a_Src.x, a_Src.y, a_Src.z, a_Offset.x, a_Offset.y, a_Offset.z, a_ParticleData, a_ParticleAmount); | ||
| } | ||
| void cProtocol172::SendPlayerListAddPlayer(const cPlayer & a_Player) | ||
| @@ -99,6 +99,7 @@ class cProtocol172 : | ||
| virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; | ||
| virtual void SendPaintingSpawn (const cPainting & a_Painting) override; | ||
| virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; | ||
| virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> data) override; | ||
| virtual void SendPickupSpawn (const cPickup & a_Pickup) override; | ||
| virtual void SendPlayerAbilities (void) override; | ||
| virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override; | ||
Oops, something went wrong.